<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>模拟刷卡进出</title>
	<script src="../../js/materialize.min.js"></script>
    <script src="../../layuilay/layui.js" charset="utf-8"></script>
    <script src="../../js/jquery-3.4.1.min.js" charset="utf-8"></script>
    <link rel="stylesheet" href="../../layuilay/css/layui.css"  media="all">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,400">
    <link rel="stylesheet" href="../../css/bootstrap.min.css">
    <link rel="stylesheet" href="../../css/materialize.min.css">
    <link rel="stylesheet" href="../../css/tooplate.css">
    
</head>

<body id="login">
    <div class="container">
        <div class="row tm-register-row tm-mb-35">
            <div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 tm-login-l">
                <div  class="tm-bg-black p-5 h-100">
               
                   
                    <div class="input-field">
                       <!--  <input  id="rea_staus" type="text"  class="validate"> -->
                   <button type="button" onclick="admin(1)">教师</button>
                   <button type="button" onclick="admin(2)">学生</button>
                   <button type="button" onclick="admin(3)">管理员</button>
                   <button type="button" onclick="admin(4)">馆长</button>
                   <input  id="input1" type="text"  class="validate" style="color: blue;" readonly="readonly"/>
                   <input  id="input2" type="text" hidden="none"    class="validate">
                    </div>
                    <script type="text/javascript">
                    function admin(i){
                    	 $("#input2").val(i);
                        if(i == 1){
                            $("#input1").val("你所选择的身份为：教师");
                            }else if(i==2){
                            	$("#input1").val("你所选择的身份为：学生");
                            }else if(i==3){
                            	$("#input1").val("你所选择的身份为：管理员");
                            }else if(i==4){
                            	$("#input1").val("你所选择的身份为：馆长");
                            }
                        }

                    </script>
                    
                    
                    
                    <div class="input-field">
                        <input  id="rea_rid" type="text" placeholder="账号ID" class="validate">
                    </div>
                    <div class="input-field mb-5">
                        <input id="rea_pwd"  type="password" placeholder="密码" class="validate">
                    </div>
                    <div class="tm-flex-lr">
                        <a href="#" class="white-text small"></a>
                        <button type="button" id="entrance" class="waves-effect btn-large btn-large-white px-4 black-text rounded-0">进入</button>
                        <button type="button" id="departure" class="waves-effect btn-large btn-large-white px-4 black-text rounded-0">离开</button>
                    </div>
                </div>
            </div>
            <div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 tm-login-r">
                <header class="font-weight-light tm-bg-black p-5 h-100">
                    <h3 class="mt-0 text-white font-weight-light">欢迎进入</h3>
                    <p>欢迎您来到图书馆，书籍是人类进步的阶梯，用心领悟知识，用心爱护图书，进入请勿大声喧哗</p>
                    <p class="mb-0">Welcome to the library, books are the ladder of human progress, understand the knowledge attentively, love the books attentively, please do not make loud noises when entering</p>
                </header>
            </div>
        </div>
       
       
    </div>
    <script>
    layui.use(['jquery','layer'], function(){
    	 var $ = layui.$;
         var layer = layui.layer;
    

    $(function(){
        $("#entrance").click(function(){
            var rea_rid = $('#rea_rid').val();
            var rea_pwd = $("#rea_pwd").val();
            var rea_staus = $("#input2").val();
            if (rea_staus == ""){
                layer.msg("请选择身份！");
                flag = false;
                return false;
            }else if (rea_rid == ""){
            	layer.msg("请输入账号！");
                flag = false;
                return false;
            }else if (rea_pwd == ""){
            	layer.msg("请输入密码！");
                flag = false;
                return false;
            }else{
            	$(this).attr("disabled","disabled");
                }
            if(flag == true){
            	
                return true;
            }
           var flag= $.ajax({
                url:"../../findByR_idAndpassword",
                data:{
                    r_id:rea_rid,
                    staus:rea_staus,
                    password:rea_pwd
                },
                dataType:"json",
                type:"post",
                success:function(res){
                    if(res.success){
                    	var staus=  res.object.staus;
                    	if(staus==1){
                    		staus="老师";
                        }else if(staus==2){
                        	staus="学生";
                        }else if(staus==3){
                            staus="图书管理员";
                        }else if(staus==4){
                            staus="馆长";
                        }else{
                        	staus="其他";
                            }
                    	var myDate = new Date();
                        var yea = myDate.getFullYear();    // 获取完整的年份(4位,1970-????)
                        var mon = myDate.getMonth()+1;       // 获取当前月份(0-11,0代表1月)
                        var dat = myDate.getDate();        // 获取当前日(1-31)
                        var hou = myDate.getHours();       // 获取当前小时数(0-23)
                        var min = myDate.getMinutes();     // 获取当前分钟数(0-59)
                        var sec = myDate.getSeconds();     // 获取当前秒数(0-59)
                        var startTime =yea+"-"+mon+"-"+dat+" "+hou+":"+min+":"+sec;//获取的时间字符串
                            var personid = res.object.r_id;
                            var dname = res.object.name;
                            var entertime = startTime;
                            $.post("../../addDetailed",{
                                dname:dname,
                                personid:personid,
                                status:staus,
                                entertime:entertime
                                },function(res){
                                	
                                	var did = res.object.did;
                                	window.localStorage.setItem("endid",res.object.did);
                                	window.localStorage.setItem("endtime",res.object.leavetime);
                                    if(res.success){
                                    	alert("欢迎"+staus+":"+dname+"刷卡进入成功");
                                    	 
                                        }
                                    
                                    },"json");
                    	 
                    	
                    }else{
                    	layer.msg("账号或密码输入错误");
                    }
                }
               
            })
           
        })
           $("#departure").click(function(){
        	   var myDate = new Date();
               var yea = myDate.getFullYear();    // 获取完整的年份(4位,1970-????)
               var mon = myDate.getMonth()+1;       // 获取当前月份(0-11,0代表1月)
               var dat = myDate.getDate();        // 获取当前日(1-31)
               var hou = myDate.getHours();       // 获取当前小时数(0-23)
               var min = myDate.getMinutes();     // 获取当前分钟数(0-59)
               var sec = myDate.getSeconds();     // 获取当前秒数(0-59)
               var endTimes =yea+"-"+mon+"-"+dat+" "+hou+":"+min+":"+sec;//获取的时间字符串
               var endtime= window.localStorage.getItem("endtime");
               var endtime = endTimes;
               var enddid= window.localStorage.getItem("endid");
               $.post('../../updateTime',{
            	   did:enddid,
            	   endtime:endtime
                   },function(res){
                       if(res.success){
                    	   alert("刷卡离开成功");
                    	   window.location.href="../pre/index.html";
                    	   window.history.back(-1);
                           }
                   },'json');
    })
    })
    })
    </script>
</body>

</html>